package com.yq.cp.utils;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


/***
 * 拦截器,单例
 */
public class BootInterceptor implements HandlerInterceptor {

    // 1
    public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object arg2) {
        long begin_nao_time = System.nanoTime();
        req.setAttribute("begin_time", begin_nao_time);
        return true;
    }

    /*3*/
    public void afterCompletion(HttpServletRequest req, HttpServletResponse resp, Object arg2, Exception arg3)
            throws Exception {
        long beginTime = (Long) req.getAttribute("begin_time");
        long overTime = System.nanoTime();
        long aa=(overTime-beginTime)/1000000;
        String uri = req.getRequestURI();
//        System.out.println("--------------------"+uri+"-----------------------------");
    }

    /* 2 */
    public void postHandle(HttpServletRequest req, HttpServletResponse resp, Object arg2, ModelAndView arg3)throws Exception {}
}
